package cn.ziroom.webservice;

import javax.jws.WebMethod;
import javax.jws.WebService;

import cn.ziroom.contract.data.ContractData;
import cn.ziroom.contract.data.CustomerData;
import cn.ziroom.contract.data.HouseData;
import cn.ziroom.contract.data.RoomData;
import cn.ziroom.contract.service.ContractService;
import cn.ziroom.contract.service.RoomService;
import cn.ziroom.system.domain.Message;
import cn.ziroom.system.service.MessageService;

/**
 * 同步资产业务数据的接口
 * 
 * @author Administrator
 * 
 */
@WebService(name = "ziruService")
public class ZiruContractInterface {

	private ContractService contractService; // 合同的服务接口

	private RoomService roomService; // 房间的服务接口

	private MessageService messageService; // 消息的服务器接口

	/**
	 * 接口1 收房业务数据同步方法,
	 * 
	 * @param data
	 * @return
	 * @throws Exception
	 */
	@WebMethod
	public String reciveContract(ContractData data) {

		String ret = contractService.synchroReciveContract(data);

		Message msg = new Message();
		msg.setFunctionName("synchroReciveContract");
		msg.setContractCode(data.getContractCode());
		msg.setHouseCode(data.getHouseCode());
		msg.setCustomerCode(data.getCustCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;
	}

	/**
	 * 出房合同业务信息同步
	 * 
	 * @param outContractData
	 * @return
	 */
	@WebMethod
	public String outContract(ContractData outContractData) {

		String ret = contractService.synchroOutContract(outContractData);

		Message msg = new Message();
		msg.setFunctionName("synchroOutContract");
		msg.setContractCode(outContractData.getContractCode());
		msg.setHouseCode(outContractData.getHouseCode());
		msg.setCustomerCode(outContractData.getCustCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;

	}

	/**
	 * 合同违约，到期处理
	 * 
	 * @param channelContract
	 * @return
	 */
	@WebMethod
	public String channContract(ContractData channelContract) {

		String ret = contractService.synchroChannelContract(channelContract);

		Message msg = new Message();
		msg.setFunctionName("synchroChannelContract");
		msg.setContractCode(channelContract.getContractCode());
		msg.setHouseCode(channelContract.getHouseCode());
		msg.setCustomerCode(channelContract.getCustCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;
	}

	/**
	 * 房屋或房间预订业务处理
	 * 
	 * @return
	 */
	@WebMethod
	public String reservation(HouseData houseData) {

		String ret = roomService.synchroReservation(houseData);

		Message msg = new Message();
		msg.setFunctionName("synchroReservation");
		msg.setHouseCode(houseData.getHouseCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;
	}

	/**
	 * 合同作废业务数据同步
	 * 
	 * @param contractCode
	 * @return
	 */
	@WebMethod
	public String invalidContract(ContractData contractData) {

		String ret = contractService.synchroInvalidContract(contractData);

		Message msg = new Message();
		msg.setFunctionName("synchroInvalidContract");
		msg.setHouseCode(contractData.getHouseCode());
		msg.setContractCode(contractData.getContractCode());
		msg.setCustomerCode(contractData.getCustCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;
	}

	/**
	 * 合同信息的数据同步
	 * 
	 * @param contractData
	 * @return
	 */
	@WebMethod
	public String modifyContract(ContractData contractData) {

		String ret = contractService.synchroModifyContract(contractData);

		Message msg = new Message();
		msg.setFunctionName("synchroModifyContract");
		msg.setHouseCode(contractData.getHouseCode());
		msg.setContractCode(contractData.getContractCode());
		msg.setCustomerCode(contractData.getCustCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;
	}

	/**
	 * 房屋信息同步处理方法
	 * 
	 * @param houseData
	 * @return
	 */
	@WebMethod
	public String house(HouseData houseData) {

		String ret = roomService.synchroHouse(houseData);

		Message msg = new Message();
		msg.setFunctionName("synchroHouse");
		msg.setHouseCode(houseData.getHouseCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;
	}

	/**
	 * 房间信息同步
	 * 
	 * @param roomData
	 * @return
	 */
	@WebMethod
	public String room(RoomData roomData) {

		String ret = roomService.synchroRoom(roomData);

		Message msg = new Message();
		msg.setFunctionName("synchroRoom");
		msg.setRoomCode(roomData.getRoomCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;

	}

	/**
	 * 房间图片信息同步
	 * 
	 * @param roomData
	 * @return
	 */
	@WebMethod
	public String roomPictures(RoomData roomData) {

		String ret = roomService.synchroRoomPictures(roomData);

		Message msg = new Message();
		msg.setFunctionName("synchroRoomPictures");
		msg.setRoomCode(roomData.getRoomCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;
	}

	/**
	 * 删除房间图片信息
	 * 
	 * @param list
	 * @return
	 */
	@WebMethod
	public String delRoomRegion(Integer sysRoomId, String key, Integer sysHouseId) {

		String ret = roomService.synchroDelRoomRegion(sysRoomId, key, sysHouseId);

		Message msg = new Message();
		msg.setFunctionName("synchroDelRoomRegion");
		msg.setRoomCode("" + sysRoomId);

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;
	}

	/**
	 * 客户资料信息同步
	 * 
	 * @param list
	 * @return
	 */
	@WebMethod
	public String customer(CustomerData customerData) {

		String ret = contractService.synchroCustomer(customerData);

		Message msg = new Message();
		msg.setFunctionName("synchroCustomer");
		msg.setCustomerCode(customerData.getCustCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;
	}

	/**
	 * 房间物品信息同步
	 * 
	 * @param roomData
	 * @return
	 */
	@WebMethod
	public String roomConfigItem(RoomData roomData) {

		String ret = roomService.synchroRoomConfig(roomData);

		Message msg = new Message();
		msg.setFunctionName("synchroRoomConfig");
		msg.setRoomCode(roomData.getRoomCode());

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);

		return ret;
	}

	public void setContractService(ContractService contractService) {
		this.contractService = contractService;
	}

	public void setRoomService(RoomService roomService) {
		this.roomService = roomService;
	}

	public void setMessageService(MessageService messageService) {
		this.messageService = messageService;
	}
}
